package enterprises

class EnterpriseController {

    def scaffold = true
	
	def details = {
		if (!params.id) {
			redirect(action:'list')
		}
		[enterprise:Enterprise.get(params.id)]
	}
	
	def enterprisesAndProductions = {
		if (!params.id) {
			redirect(action:'list')
		}
		def typeConsumer = TypeConsumer.get(params.id);
		def enterprises = Enterprise.executeQuery("select distinct e from Enterprise as e "
			+ "join e.productions as p "
			+  "join p.consumer as c "
			+ "where c.typeConsumer.id = :typeConsumerId",
				[typeConsumerId:params.id as Long]);		
		[enterprises:enterprises, typeConsumer:typeConsumer]
	}

	@Override
	public String applicationName() {
		"Enterprises";
	}	
	
}
